package com.rosca.converters.number2word.utils;

import java.util.Stack;

/**
 * User: vrosca
 * Date: 7/27/11
 * Time: 1:01 PM
 * &copy; PFA Rosca Val Dan Dar Ion 2011
 * <p>
 * Utility functions for dealing with stacks involved in spelling
 * </p>
 */
public class StackUtils {
    /**
     * Joins spelling words into one string (LIFO)
     *
     * @param stack of spelling words
     * @param delim used to separate words
     * @return the joined string
     */
    public static String join(Stack<String> stack, String delim) {
        String joined = "";
        while (!stack.isEmpty())
            joined += stack.pop() + (stack.isEmpty() ? "" : delim);
        return joined;
    }
}
